<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../gameStyle.css" type="text/css" />
        <script type="text/javascript" src="http://lib.ivank.net/ivank.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="../lib/Box2dWeb-2.1.a.3.js"></script>
        <script type="text/javascript" src="types.js"></script>
        <script type="text/javascript" src="button.js"></script>
        <script type="text/javascript" src="timer.js"></script>
        <script type="text/javascript" src="jokes.js"></script>
    </head>
    <body onload="Start();" >
        <canvas id="canvas" width="740" height="500"></canvas>
        <script type="text/javascript">
            var canvas = document.getElementById("canvas");
            var cwidth = canvas.getAttribute("width");
            var cheight = canvas.getAttribute("height");
            
            
            
            function Start(){
                var stage = new Stage("canvas");
                
                stage.addChild(new JokeLevel(jokes[8]),0);
                var level = stage.getChildAt(0); 
                //level.type = typeJoke;
                intervalID = window.setInterval(level.run, 1000 / 60);
            }
          
            
          
            function JokeLevel(joke){
                Sprite.apply(this);
                Level.apply(this);
                this.joke = joke.text;
                this.jokeType = joke.type;
                this.answer;
                
                var jokeText = new TextField();
                jokeText.setTextFormat(JokeLevel.tFormat);
                jokeText.wordWrap = true;
                jokeText.text = this.joke;
                jokeText.width = cwidth/2 + cwidth/4; 
                jokeText.height = jokeText.textHeight;
                jokeText.x = cwidth/2 - jokeText.width/2; 
                jokeText.y = cheight/2 - 100;
                
                this.addChild(jokeText);
                
                
                const question = "Páčil sa vám tento vtip?";
                
                var questionText = new TextField();
                questionText.setTextFormat(new TextFormat(font, 20, red));
                questionText.text = question;
                questionText.width = questionText.textWidth; 
                questionText.height = questionText.textHeight;
                questionText.x = cwidth/2 - questionText.width/2; 
                questionText.y = jokeText.y + jokeText.height + 30;
                
                this.addChild(questionText);
                
                // CREATE BUTTONS
                yesButton = new Button("Áno");
                yesButton.x = cwidth/2 - yesButton.width;  
                yesButton.y = jokeText.y + jokeText.height + 60;
                yesButton.addEventListener(MouseEvent.CLICK, clickYes);
                
                this.addChild(yesButton);

                noButton = new Button("Nie");
                noButton.x = cwidth/2 + MARGIN;  
                noButton.y = jokeText.y + jokeText.height + 60;
                noButton.addEventListener(MouseEvent.CLICK, clickNo);
                
                this.addChild(noButton);
                
                function clickYes(e) {
                    //alert("yes");
                    this.answer = true;
                }
                function clickNo(e) {
                    //alert("no");
                    this.answer = false;
                }
                
            }
            JokeLevel.prototype = new Sprite();
            // JokeLevel.prototype = new Level();
            JokeLevel.tFormat   = new TextFormat(font, 30, black);
            JokeLevel.tFormat.align = TextFormatAlign.CENTER;
            
            
            

        </script>
        <script type="text/javascript" src="level.js"></script>
    </body>
</html>
